<?php
/**
 * Zead
 *
 * LICENSE	
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/bsd-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to eu@marcelomx.com so we can send you a copy immediately.
 *
 * @category   Zead
 * @author     Marcelo Rodrigues Gonzaga <eu@marcelomx.com>
 * @copyright  Copyright (c) 2008 Marcelo Rodrigues Gonzaga
 * @link       http://code.google.com/p/zead 
 * @license    http://www.opensource.org/licenses/bsd-license.php     New BSD License
 *
 **/


/** @see Zead_Player_Plugin_Abstract **/
require_once 'Zead/Player/Plugin/Abstract.php';

/** @see Zead_Manifest **/
require_once 'Zead/Manifest.php';

/** @see Zend_Cache **/
require_once 'Zend/Cache.php';

/**
 * @category   Zead
 * @package    Zead_Player
 * @package    Zead_Player_Plugin
 * @copyright  Copyright (c) 2008 Marcelo Rodrigues Gonzaga 
 * @license    http://www.opensource.org/licenses/bsd-license.php     New BSD License 
 */
class Zead_Player_Plugin_Manifest extends Zead_Player_Plugin_Abstract 
{
	/**
	 * Executando o plugin antes da inicialização da ação.
	 * 
	 */
	public function preDispatch() 
	{
		$player = $this->getPlayer();		
		// Gerando dados para o cache
		$basePath = $player->credential['basePath'];

/*		$cacheId = md5($basePath);

		// Opções do cache
		$frontendOptions = array(
			'lifetime' => 30,
			'automatic_serialization' => true
		);
		$backendOptions = array(
			'cache_dir' => $player->getParam('cacheDir')
		);
		$cache = Zend_Cache::factory('Output', 'File', $frontendOptions, $backendOptions);
			
		// Tentando carregar os dados gravados em cache
		if (!($manifest = $cache->load($cacheId))) {
			$fileName = $basePath . '/manifest.xml';
			$adapter  = new Zead_Manifest_Adapter_Xml(array('string' => (string) file_get_contents($fileName)));
			$manifest = $adapter->getManifest();
			$cache->save($manifest, $cacheId);
		}*/
		$fileName = $basePath . '/manifest.xml';		
		$manifest = Zead_Manifest::factory('Xml', $fileName);
				
		// Registrando os metadados				
		$player->manifest = $manifest;
	}
}

